package com.li.taskcenter.service.taskdefine.impl;

import com.github.pagehelper.PageInfo;
import com.li.configserve.domain.gloabreturn.ResponseInfo;
import com.li.taskcenter.domain.taskcenter.TaskDefine;
import com.li.taskcenter.domain.taskcenter.TaskDefineExample;
import com.li.taskcenter.mapper.taskcenter.TaskDefineMapper;
import com.li.taskcenter.service.taskdefine.TaskDefineService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description：TaskDefineService实现类
 * @Author：LiDong
 * @Create：2020/11/30
 * @Version：1.0.0
 */
@Service
public class TaskDefineServiceImpl implements TaskDefineService {

    private static final Logger logger = LoggerFactory.getLogger(TaskDefineServiceImpl.class);

    @Autowired
    private TaskDefineMapper taskDefineMapper;

    /**
     * @return com.li.configserve.domain.gloabreturn.ResponseInfo
     * @Author LiDong
     * @Description //TODO 任务定义分页查询接口实现
     * @Date 20:28 2020/11/30
     * @Param [paramMap]
     *
     * @param paramMap*/
    @Override
    public ResponseInfo pageTaskDefines(Map<String, String> paramMap) {
        ResponseInfo responseInfo = new ResponseInfo();
        try {
            List<TaskDefine> taskDefines = taskDefineMapper.selectByExample(new TaskDefineExample());
            PageInfo<TaskDefine> pages = new PageInfo<>(taskDefines);
            responseInfo.setData(pages);
            responseInfo.setCode(200);
            responseInfo.setMessage("查询成功！");
            return responseInfo;
        } catch (Exception e) {
            logger.info(e.getMessage(), e);
            responseInfo.setCode(500);
            responseInfo.setMessage(e.getMessage());
            responseInfo.setData(e);
            return responseInfo;
        }
    }

    /**
     * 任务定义新增
     *
     * @param taskDefine
     * @return
     */
    @Override
    public ResponseInfo addTaskDefine(TaskDefine taskDefine) {
        try {
            Integer id = taskDefine.getId();
            if (StringUtils.isNotEmpty(String.valueOf(id))) {
                // 更新
                return ResponseInfo.success(200, "更新成功！");
            }
            return ResponseInfo.success(200, "保存成功！");
        } catch (Exception e) {
            logger.error("error occur:", e);
            return ResponseInfo.error(500, e.getMessage());
        }
    }
}
